using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using ZWFrameWork;

namespace Watermelon
{
    public enum ShipTypeEnum
    {
        boat_fan,
        boat_fishing_small,
        boat_house_a,
        boat_house_b,
        boat_house_c,
        boat_house_d,
        boat_row_large,
        boat_row_small,
        boat_sail_a,
        boat_sail_b,
        boat_speed_a,
        boat_speed_b,
        boat_speed_c,
        boat_speed_d,
        boat_speed_e,
        boat_speed_f,
        boat_speed_g,
        boat_speed_h,
        boat_speed_i,
        boat_speed_j,
        boat_tow_a,
        boat_tow_b,
        boat_tug_a,
        boat_tug_b,
        boat_tug_c,
        ship_cargo_a,
        ship_cargo_b,
        ship_cargo_c,
        ship_ocean_liner,
        ship_ocean_liner_small,
        max,
    }

    public class ShipInfoManager : SingletonInstance<ShipInfoManager>
    {
        Dictionary<ShipTypeEnum, List<GameObject>> mAllShipDic;

        public void OnLoadAllShip()
        {
            mAllShipDic = new Dictionary<ShipTypeEnum, List<GameObject>>();
            for (int i = 0; i < (int)ShipTypeEnum.max; i++)
            {
                ShipTypeEnum tempenum = (ShipTypeEnum)i;
                GameObject resload = Resources.Load<GameObject>("GameRes/Prefab/ShipSkin/" + tempenum);
                mAllShipDic.Add(tempenum, new List<GameObject>(){resload});
            }
        }

        public GameObject OnGetShip(ShipTypeEnum shipenum)
        {
            if (mAllShipDic.ContainsKey(shipenum))
            {
                if (mAllShipDic[shipenum].Count <= 1)
                {
                    GameObject yuzhiti = GameObject.Instantiate(mAllShipDic[shipenum][0]);
                    yuzhiti.SetActive(false);
                    mAllShipDic[shipenum].Add(yuzhiti);
                }
                return mAllShipDic[shipenum][1];
            }

            return null;
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitData()
        {
            OnLoadAllShip();
        }

        /// <summary>
        /// 清理数据
        /// </summary>
        public override void ClearData()
        {
            for (int i = 0; i < mAllShipDic.Count; i++)
            {
                if (mAllShipDic[(ShipTypeEnum)i] != null && mAllShipDic[(ShipTypeEnum)i].Count >= 2)
                {
                    GameObject.Destroy(mAllShipDic[(ShipTypeEnum)i][1]);
                }
            }
            mAllShipDic.Clear();
            mAllShipDic = null;
        }
    }
}
